package com.qyer.lxp.action;

import com.qyer.lxp.common.date.DateUtil;
import com.qyer.lxp.model.product.normal.ProductCodeInfo;
import com.qyer.lxp.model.product.parameter.ProductCodeSearchRequest;
import com.qyer.lxp.service.product.IProductService;
import com.qyer.lxp.service.product.impl.ProductServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 产品相关接口测试
 * Created by jiangping on 16/5/13.
 */

public class GetProductCode extends AbstractJUnit4SpringContextTests {

    private IProductService productService;

    /**
     *  获取产品code以及更新时间接口
     */
    public void getProductCode(){

        ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "classpath*:*Context*.xml" });

        //实例化预警所有的启动任务
        productService = (IProductService) ctx.getBean(ProductServiceImpl.class);

        Map<String,String> mapProductCode=new HashMap<String,String>();
        ProductCodeSearchRequest productCodeSearchRequest = new ProductCodeSearchRequest();
        try {
            productCodeSearchRequest.setUpdateDateStart(DateUtil.convertDate("2014-01-01"));
            //productCodeSearchRequest.setUpdateDateEnd(DateUtil.convertDate("2016-05-30"));

        } catch (Exception e) {
            e.printStackTrace();
        }

        int num=100;//获取的条数
        int result_num=100;//获取力行返回的结果数量

        int start_index=1;
        int end_index=100;
        while(result_num==num){

            productCodeSearchRequest.setStart(start_index);
            productCodeSearchRequest.setEnd(end_index);
            List<ProductCodeInfo> productCodeInfoList = productService.getUpdateProductInfo(productCodeSearchRequest);
            result_num=productCodeInfoList.size();
            for (ProductCodeInfo p:productCodeInfoList){
                if(!p.getLastUpdateAction().equals("OFF_SHELF")){
                    mapProductCode.put(p.getProductCode(), p.getLastUpdateAction());
                }

            }
            start_index=start_index+num;
            end_index=end_index+num;
        }

        System.out.println("总共商品：" + mapProductCode.size());
    }

    public static void main(String[] args) {
        GetProductCode code=new GetProductCode();
        code.getProductCode();
    }
}
